home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / buckbook.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  34KB  |  1,201 lines

  1. /*
  2.     Fred Peachman KB7YW
  3.     7186 Northview Drive
  4.     Brookfield, OH 44403
  5.  
  6.     Fri  05-08-1992
  7.     OK here is my "final" product for the Buckmaster "HamCall" CD-ROM based
  8.     callsign server. 
  9.  
  10.    It is a substitute for N4PCR's callsign server. The intent is to replace
  11.    N4PCR's callbook.c with this file - and have a callsign server that will
  12.    run off Buckmaster's CD-ROM: the October 1991 "HAM CALL" CD.(or May  '92)
  13.  
  14.    The CD-ROM must be configured with a driver installed in config.sys,
  15.    and the mscdex.exe TSR must be running.
  16.  
  17.    This module can be compiled one of two ways.
  18.  
  19.     In config.h:
  20.  
  21.    - If CALLSERVER is defined, but ICALL is not:
  22.       you get the same sort of callsign server that I did for the
  23.       October '91 Ham Call CD. It is compatible with either the October
  24.       '91 CD or the May '92 CD. The October '91 CD can utilize the
  25.       Canadian Callsign database as well as the U.S. The May '92 CD does
  26.       not provide the separate Canadian callsign database so the
  27.       "callserver database canadian" command should not be used in
  28.       autoexec.nos. One new feature to this old server is provision for
  29.       "cross-referencing", a feature that is new with May '92 HamCall CD
  30.       but not on the October '91 CD.
  31.  
  32.    - If ICALL is defined, you get the international callsign database
  33.       that is new for the May '92 HamCall CD. The international callsign
  34.       database contains U.S., Canadian and a smattering of foreign callsigns.
  35.       It is based on shelling out to Buckmaster's icall.exe utility which
  36.       is located in the root directory of the May '92 CD. THIS option is
  37.       NOT available on the October '91 HamCall CD!!
  38.  
  39.         To set it up, you use the "cdrom" command to tell NOS the drive
  40.       letter of your CD-ROM drive. You set yourself up as the callserver
  41.       with "callserver hostname <hostname>". You "start callbook". That's it!
  42.  
  43.       - de KB7YW
  44.  
  45.    ---------------------------------------------------------------------------
  46.    - for CALLSERVER:
  47.    Wed  04-29-1992 Mods for the May '92 callbook server. Buckmaster does
  48.    not provide a separate Canadian callsign database on this CD. So this
  49.    code will only be good for the USA database: "s:\\ham0\\hamcall.129".
  50.    "Cross-referencing" works: For a callsign which has changed, the old
  51.    call will be displayed, the date it was changed will be given, and the
  52.    amateur's directory listing under his new callsign will be given. As
  53.    for ICALL, since this is a simple shell to Buckmaster's icall.exe
  54.    utility, I cannot add cross-referencing!
  55.  
  56.    The callserver database commands will configure the cd-rom.
  57.  
  58.    config.h must #define CALLCLI or CALLSERVER. If CALLSERVER is #define'd
  59.    CALLCLI is forced on by config.h. Only CALLCLI can be #define'd separately
  60.    of CALLSERVER so it is the default condition for compilation of this
  61.    module - which won't used at all if neither CALLCLI nor CALLSERVER are
  62.    #define'd in config.h.
  63.  */
  64.  
  65. #include <stdio.h>
  66. #include <string.h>
  67. #include <time.h>
  68. #include <sys/timeb.h>
  69. #include "global.h"
  70. #include "files.h"
  71. #include <stdlib.h>
  72. #ifdef MSDOS
  73. #include  <dos.h>
  74. #include <alloc.h>
  75. #endif
  76. #include <ctype.h>
  77. #include <fcntl.h>
  78. #ifdef MSDOS
  79. #include <io.h>
  80. #endif
  81.  
  82. #include "cmdparse.h"
  83. #include "ftp.h"
  84. #include "config.h"
  85.  
  86. /* if ICALL is defined, it forces CALLSERVER to be defined. However, if
  87.   CALLSERVER is defined, it does not force ICALL. Therefore definition of
  88.   ICALL controls which server code gets compiled.
  89.  
  90.   If neither CALLSERVER nor ICALL is defined, this module might still be
  91.   needed if CALLCLI is defined, for the callserver client code.
  92.  
  93.  */
  94.   struct months {
  95.     char *m;  /* name of month  */
  96.     int  d;   /* days in month  */
  97.   };
  98.  
  99. #ifdef ICALL
  100. #ifndef CALLSERVER
  101. #define CALLSERVER 1
  102. #endif    /* #ifndef CALLSERVER */
  103. #endif    /* #ifdef ICALL */
  104.  
  105. char  *Callserver = NULLCHAR;
  106. static int
  107. docallserver_hostname(int argc,char *argv[],void *p);
  108.  
  109. #ifdef CALLSERVER
  110. static int
  111. docallserver_databases(int argc,char *argv[],void *p);
  112.  
  113. /* CD-ROM code by Fred Peachman KB7YW */
  114. char *CDROM = NULLCHAR;
  115. char *cdrom_prompt =
  116.             "\tUse the \"cdrom\" command to specify CD-ROM's drive letter\n";
  117. struct months month[12] = {
  118.   {"January", 31},{"February",28},{"March",31},{"April",30},{"May",31},
  119.   {"June",30},{"July",31},{"August",31},{"September",30},{"October",31},
  120.   {"November",30},{"December",31}
  121.   };
  122.  
  123. #ifndef ICALL
  124. /* What follows is the original stuff for the Oct '91 Ham Call CD:  */
  125.  
  126. /*struct database_activity
  127.   One of these structs gets filled out by init -
  128.   initializes data base for calls from hamcall.c -
  129.   should be able to handle generic functions across different data base
  130.   formats.
  131.  */
  132.   struct database_activity {
  133.     int type;                     /* for checking data/function formats*/
  134. #define USA 0
  135. #define CANADA 1
  136.     int  handle;                  /* -1 if unitialized  */
  137.     unsigned long record;         /* current record #                 */
  138.     void *record_buf;           /* where to read the record to      */
  139.   };
  140.  
  141. /* The Buckmaster HAM CALL CD format for U.S. Callsign database       */
  142.   struct usa  {
  143.     char callsign[6];   /* None of these fields are ASCIIZ so be careful */
  144.     char lastname[24];
  145.     char firstname[11];
  146.     char middle[1];
  147.     char street[35];
  148.     char city[20];
  149.     char state[2];
  150.     char zip[5];
  151.     char fluff[8];      /* supreme nothingness                            */
  152.     char exp[2];        /* 'X3' if license expired                        */
  153.     char born[2];       /* Last two digits of year of birth  i.e. '54     */
  154.     char expiryr[2];    /* Last two digits of year of license expiration  */
  155.     char expirday[3];   /* The day of the year that license expires       */
  156.     char validyr[2];    /* year that license was issued                   */
  157.     char validday[3];   /* day of the year that license was issued        */
  158.     char class[1];      /* 1 letter license classification                */
  159.     char endline[2];    /* file marker                                    */
  160.   };
  161.  
  162. /* The Buckmaster HAM CALL CD format for Canadian Callsign database
  163.    It is 0x9a bytes long (154) The first record has a blank callsign field
  164.    that should be no problem!                                             */
  165.  
  166.   struct canada  {
  167.     char callsign[8];
  168.     char name[0xe8 - 0xa2];
  169.     char street[0x10a - 0xe8];
  170.     char town[0x121-0x10a];
  171.     char province[0x12c-0x121];
  172.     char zip[6];
  173.     char endline[2];
  174.   };
  175.                     /* generic function calls: headers */
  176. static int
  177. init(struct database_activity *db,int type,int s);
  178. static int
  179. close_down(struct database_activity *db);
  180. static void
  181.  disp(char *cfield, int siz, int s);
  182. static int
  183. readrec(struct database_activity *db);
  184. static int
  185. displayrec(struct database_activity *db, int s);
  186. static int
  187. find_call(struct database_activity *db, char *callsign);
  188. static int
  189. make_mask(char *mask, char *callsign, int s);
  190.  
  191.                         /* for u.s.a database:  */
  192. static int
  193. display_usa(void *,int s);
  194. static int
  195. comp_usa_calls(char *, char *);
  196.  
  197.                         /* for canada database  */
  198. static int
  199. display_canada(void *,int s);
  200. static int
  201. comp_canada_calls(char *, char *);
  202.  
  203. /* most of this module is server code, but some is client: CALLCLI is by
  204.    default - forced on in config.h whenever CALLSERVER is #define'd */
  205.  
  206. /* How many different databases are we supporting right now?              */
  207. #define DATABASE_TYPES 2
  208.  
  209. /* how many passes should we make before we give up (in find_call)?    */
  210. #define MAXREADS 30
  211. /*----------------------------------------------------------------------------
  212.  
  213.     Here are arrays of variables to use depending on which database is
  214.     needed. In each array make sure the value order is same as defs for
  215.     database_activity.types i.e. USA, CANADA, ....
  216.  
  217.     In order to tack on another database, add an element for each of these
  218.     arrays, increment the definition for DATABASE_TYPES (above), and
  219.     tell your program how to tell init to use the new one.  In this
  220.     module the launcher (cb_lookup) will figure out which database to
  221.     initialize ("init(type, callsign,s)").
  222.  
  223.     Basically for the new database you would only need to specify its file
  224.     name in database[], write a display function and specify it in
  225.     displayfunc[], specify the size of one record in record_size[],
  226.     write a callsign comparison function and specify it in compare_calls[],
  227.     and specify the byte offset of the callsign field within a record -
  228.     specify this offset in call_offset[] - it will probably be 0 anyway.
  229.  
  230.     You need to write something in cb_lookup to tell init when to initialize
  231.     your new database. Basically if "call" satisfies inspection, initialize
  232.     the appropriate database.
  233.  */
  234.  
  235. char *database[DATABASE_TYPES]  = {
  236.   { NULLCHAR  }, /* "S:\\HAM0\\HAMCALL.129"},  USA  */
  237.   { NULLCHAR  }  /* "S:\\HAM0\\CANADA2.DAT"}   CANADA */
  238. };
  239.  
  240. char *database_label[DATABASE_TYPES]  = {
  241.   { "usa"},{"canadian"}
  242. };
  243.  
  244. int (*displayfunc[DATABASE_TYPES])(void *, int) = {
  245.   { display_usa },
  246.   { display_canada }
  247. };
  248.  
  249. /* basic record size, in bytes, in each database  */
  250. int record_size[DATABASE_TYPES] =   {   129, 154  };
  251.  
  252.             /* How fresh is this stuff in the database?
  253.             Wed  04-29-1992  Now handled by getftime  - KB7YW
  254. static char *Volume = "October 1991";
  255.               */
  256.  
  257.             /* number of records in each type of database */
  258. unsigned long records[DATABASE_TYPES];
  259.  
  260.        /* The database-specific callsign comparison procedure  */
  261. int (*compare_calls[DATABASE_TYPES])(char *,char *) = {
  262.   {comp_usa_calls},{comp_canada_calls}
  263. };
  264. /*      At what offset within a database struct is the callsign located?
  265.                Look at struct usa and struct canada above
  266.  */
  267. int call_offset[DATABASE_TYPES] = { 0,0 };
  268.  
  269. /*
  270. char *BusyServer = "\n\nThe callsign server is busy right now\n\
  271. .... please call back later\n\n";
  272.  */
  273.  
  274. char *Db_Unavail = "\n\nDatabase is not available.\n";
  275.  
  276. char *Db_Not_config = "\n\nDatabase is not configured.\n";
  277.  
  278. static char *TAB = "        ";
  279.  
  280. /*--------------------------------------------------------------------------*/
  281. /* --------------- Generic (database-independent) functions ----------------*/
  282. /*----------------------------------------------------------------------------
  283.   Initialize a database activity struct. this consists of making sure
  284.   the database file is opened and that the number of records in that
  285.   file is computed. Also a record_buf is malloced for each db.
  286.  */
  287. static int
  288. init(db, type, s)
  289. struct database_activity *db;
  290. int type;
  291. int s;
  292. {
  293. long tmp;
  294. int i;
  295. extern char *Callserver;  /* declared in calldbd.c  */
  296.   if ((type < 0) || (type >= DATABASE_TYPES))  return -1;
  297.  
  298.   db->type = type;
  299.  
  300.   if (database[type] == NULLCHAR)  {
  301.     usprintf(s,"%s",Db_Not_config);
  302.     return -1;
  303.   }
  304.  
  305.   i = db->handle = _open(database[type], O_RDONLY | O_BINARY);
  306.   if (i == -1) {
  307.     usprintf(s,"%s",Db_Unavail);
  308.     return -1;
  309.   }
  310.   for (i = 0; i < 50; i++)  pwait(NULL);
  311.   /* The CD-ROM is a slow device!! - give other processes lots of slack */
  312.  
  313.   tmp = filelength(db->handle);
  314. /*   if (tmp == -1L)  {
  315.     usprintf(s,"Error reading length of file \"%s\"\n\
  316.     please report to the sysop at %s\n",database[type], Callserver);
  317.     return -1;
  318.   }
  319. */
  320.   records[type] = tmp/((long) record_size[type]);
  321.  
  322.   db->record_buf = (char *)malloc(record_size[type]);
  323.   if (db->record_buf == NULL) {
  324.     usprintf(s,"%s",Db_Unavail);  /* No memory to allocate, actually  */
  325.     return -1;
  326.   }
  327.   return 0;
  328. }
  329.  
  330. static int
  331. close_down(db)
  332. struct database_activity* db;
  333. {
  334.   free(db->record_buf);
  335.   _close(db->handle);
  336.   return 0;
  337. }
  338. static int
  339. invalid_callsign(callsign, s)
  340. char *callsign;
  341. int s;
  342. {
  343.   usprintf(s,"\n\n\"%s\" is an invalid callsign\n\n", callsign);
  344.   return -1;
  345. }
  346.  
  347. /* make_mask makes a Buckmaster-compatible mask out of the callsign.
  348.   caller must allocate 6 bytes exactly for "mask" or 7 to make an ascii
  349.   string out of it.
  350.  
  351.   callsign is the callsign we are looking to match; mask is the same
  352.   callsign only padded to Left with a space if necessary to keep the
  353.   callsign digit at position 2 (starting with 0), and padded with spaces
  354.   to the right if necessary to make sure the mask is exactly 6 digits
  355.   long.
  356.  
  357.   This routine will work right for US or Canadian callsigns, but NOT with
  358.   foreign callsigns (that contain more than one numeric character) it
  359.   will fail!
  360.  */
  361.  
  362. static int
  363. make_mask(mask, callsign,s)
  364. char *mask;
  365. char *callsign;
  366. int s;
  367. {
  368. int j, k, len, already=0;
  369. char *q, *p;
  370. char tmp[7];
  371.  
  372.   len = strlen(callsign);
  373.  
  374.   /* there must be only ONE digit-character at position 1 or 2
  375.       (starting from 0)  */
  376.   q = callsign;
  377.   already = 0;
  378.   for (j = 0; j < len; j++)   {
  379.     if (isdigit(*q++))  {
  380.       if (!(already++)) k = j;/* already counts the number of digit chars */
  381.       else return invalid_callsign(callsign,s);
  382.     }
  383.   }
  384.   if ((k < 1) || ( k > 2))  return invalid_callsign(callsign,s);
  385.  
  386. /* FINALLY, Buckmaster pads to the left with spaces to position the digit at
  387.   mask[2] */
  388.  
  389.   q = mask;
  390.   for (j = 0; j < 6; j++) *q++ = ' '; /* initialize!  */
  391.  
  392.   p = callsign;
  393.   q = mask;
  394.  
  395.   switch (k)  {
  396.     case 1:
  397.     *q++ = ' '; /* left-pad with a space  */
  398.     break;
  399.  
  400.     case 2:
  401.     break;
  402.  
  403.     default:
  404.     break;
  405. /*  usprintf(s,"Error in make_mask %s line %d\n",__FILE__,__LINE__);
  406.     exit(255);
  407. */
  408.   }
  409.  
  410.   for (j = 0; j < len; j++) *q++ = *p++;
  411.  
  412.   return ((int) (mask[2]) &0x0f); /* returns digit of the valid U.S. callsign */
  413. }
  414.  
  415. /* a method for display of non-ASCIIZ strings */
  416. static void
  417. disp(cfield,siz,s)
  418. char *cfield;
  419. int siz;
  420. int s;
  421. {
  422. char *q;
  423. int i, sw=0;
  424.  
  425.   q = cfield;
  426.   for (i = 0; i < siz; i++) {
  427.     if ((!sw) || (*q != ' ')) usputc(s, (int) *q, stdout);
  428.     if (*q == ' ') sw = 1;
  429.     else sw = 0;  /* We will print out one space before we quit!  */
  430.     q++;
  431.   }
  432. }
  433. readrec(db)
  434. struct database_activity *db;
  435. {
  436. unsigned long filepointer;
  437. int n;
  438. int st;
  439.  
  440.   st = db->type;
  441.   filepointer = db->record*((long) record_size[st]);
  442.   lseek(db->handle, filepointer,SEEK_SET);
  443.   n = _read(db->handle, db->record_buf,record_size[st]);
  444.   if (n != -1) return 0;
  445.   else return -1;
  446. }
  447.  
  448. static int
  449. displayrec(db,s)
  450. struct database_activity *db;
  451. int s;
  452. {
  453. int (*func)(void *v, int s);
  454.  
  455.   func = displayfunc[db->type];
  456. /*   usprintf(s,"\n%s*** Record # % 8lu:***\n",TAB, db->record);  */
  457.   return func(db->record_buf,s);
  458. }
  459. /* find_call: Find the record number that matches the callsign. For any
  460.    callbook data where the records are all of the same length. The
  461.    returned record value is found as db->record.
  462.  
  463.    If the input callsign needs to be converted to a search mask in any
  464.    way, do it then call findcall.
  465.  
  466.    The returned int value is the number of records read during the search
  467.    process.
  468.  */
  469.  
  470. static int
  471. find_call(db, callsign)
  472. struct database_activity *db;
  473. char *callsign;
  474. {
  475. int i, ret, met= 0, reads = 0;
  476. long ra,rz;  /* first, middle, last record numbers */
  477. int (*comp)(char *, char *);
  478. int st;
  479. char *rec_call;
  480.  
  481.   st = db->type;  /* determine database structure type  */
  482.   comp = compare_calls[st];
  483. /* set initial pointers */
  484.   ra = 0L;
  485.   rz = records[st] - 1L;
  486.   db->record = (ra + rz)/2L;  /* go for the middle  */
  487.  
  488.   rec_call = (char *)db->record_buf + call_offset[st];
  489.   ret = 1;
  490.   while (ret != 0)  {
  491.     readrec(db);  /* read in the data pointed to by db->record  */
  492.     for (i=0; i < 50; i++)
  493.       pwait(NULL);  /* sit back and let other processes run for a while.
  494.       The CD-ROM is a slow-access device so lots of other processes may
  495.       be waiting or trying to run - like the keyboard!!! */
  496.  
  497.     reads++;
  498.     ret = comp(callsign, rec_call);
  499.  
  500.     if (ret < 0)  /* callsign < record's callsign field  */
  501.       rz = db->record - 1L;
  502.     else if (ret > 0)  /* callsign > record's callsign field  */
  503.       ra = db->record + 1L;
  504.     else return reads;
  505.  
  506.     if (reads == MAXREADS) return -1;  /* Abnormal return  */
  507.     else if (ra >= rz)  {
  508.       if (met)  return -1;
  509.       else  met = 1;  /* catch this if it happens a second time!  */
  510.     }
  511.     db->record = (ra + rz)/2L;
  512.   }
  513.   /* not reached  */
  514. }
  515. /*---------------- ROUTINES FOR U.S. CALLSIGN DATABASE ----------------------*/
  516.  
  517. /* getdaynum: given a character array 'p' of 'siz' elements, convert the
  518.    array to an ASCIIZ string, return the integer value that it
  519.    represents.
  520.  */
  521. static int
  522. getdaynum(p,siz)
  523. char *p;
  524. int siz;
  525. {
  526. char *q, tmp[80];
  527. int ret, i;
  528.  
  529.   q = p;
  530.   for (i = 0; i < siz; i++) {
  531.     tmp[i] = *q++;
  532.   }
  533.   tmp[i] = '\0';
  534.  
  535.   ret = atoi(tmp);
  536.  
  537.   return ret;
  538. }
  539. /* yrval:
  540.    Take the two-letter year code and determine if we have a year that is in
  541.    the 1900's or the 21st century. Return a proper integer answer:
  542.    i.e. "2002" or "1998".
  543.  */
  544. static int
  545. yrval(yrin)
  546. char *yrin;
  547. {
  548. int i, num;
  549.  
  550.     num = getdaynum(yrin, 2);
  551.  
  552.     if (num > 90) num += 1900;
  553.     else num += 2000;
  554.     return num; /* an integer */
  555. }
  556. /* day_calc: given the 3-element character array 'day' and the 2-element
  557.    character array 'yr', construct a string that returns the date for
  558.    that year, in the form "February 28, 2002" */
  559.  
  560. static char *
  561. day_calc(day, daystr, yr)
  562. char day[3];
  563. char *daystr;
  564. char yr[2];
  565. {
  566. int i, daynum, subt, year, t;
  567. char *q, tmp[4];
  568. int leap = 0;
  569.  
  570.     year = yrval(yr);
  571.  
  572.     if (!(year%4))  leap = 1; /* evenly divisible by four means leap year */
  573.  
  574.     daynum = getdaynum(day, 3);
  575.     if (daynum == 0)  return NULL;
  576.  
  577.  
  578.     subt = 0;
  579.     for (i = 0; i < 12; i++)  {
  580.       if (((t = subt + ((i == 1) ? leap : 0) + month[i].d)) > daynum) break;
  581.       else (subt = t);
  582.     }
  583.     t = daynum - subt;
  584.     if (i == 12)  daystr[0] = '\0';
  585.     else  sprintf(daystr,"%s %d, %d", (t > 0 ? month[i].m : month[--i].m),
  586.                   (t > 0 ? t : month[i].d + ((i==1) ? leap : 0)),
  587.                   year);
  588.     return daystr;
  589. }
  590. /* comp_usa_calls compares the sought-for callsign with a mask of the
  591.    type encountered in the callsign field of a struct usa,
  592.  
  593.   returns 0 if they match, -1 if mask1 < mask2, 1 if mask1 > mask2.
  594.   mask1 is the callsign requested, mask2 is the database callsign from
  595.   the record under test for match.
  596.  */
  597. static int
  598. comp_usa_calls(mask1, mask2)
  599. char mask1[6];
  600. char mask2[6];
  601. {
  602. int i;
  603. char *p, *q;
  604.  
  605.   /* This is in accordance with the way that Buckmaster orders callsigns
  606.      on its CD-ROM database, so follow along:
  607.    */
  608.  
  609.   p = &mask1[2], q = &mask2[2];
  610.   for (i =2; i < 6; i++)  {
  611.     if (*p != *q)  return (int) *p - (int) *q;
  612.     p++, q++;
  613.   }
  614.   p = mask1, q = mask2;
  615.   for (i =0; i < 2; i++)  {
  616.     if (*p != *q)  return (int) *p - (int) *q;
  617.     p++, q++;
  618.   }
  619.   return 0;
  620. }
  621.  
  622. /* for display of an 'X' record in a US callsign record Apr '92 HamCall CD.
  623.   first three elements of the usa struct look like this:
  624.  
  625.        callsign: ∙N8MVI
  626.        lastname: ∙CHANGED∙08/27/91∙∙∙∙∙∙∙
  627.       firstname: ∙SEE∙KF8PH∙
  628.  
  629.       where '∙' is a placeholder to show size only.
  630.       Let's do an appropriate display of this information.
  631.   */
  632.  
  633. static int
  634. display_x(us,s)
  635. struct usa *us;
  636. int s;
  637. {
  638. /*
  639.   in us->lastname, ["∙CHANGED∙08/27/91∙∙∙∙∙∙∙"] us->lastname[17] is where
  640.   to ASCIIZ-ize it. us->callsign is not NULL-terminated, and us->lastname
  641.   follows it immediately. So we will just print out the first two elements
  642.   of the structure usa:
  643.  */
  644.   us->lastname[17] = '\0';
  645. /* A NULL at us->middle will ASCIIZ-ise us->firstname, of which we want
  646.   all past the "SEE".
  647.  */
  648.   us->middle[0] = '\0';
  649.   usprintf(s,"%s\nNew callsign is \"%s\"\n\n", us->callsign, &us->firstname[5]);
  650.   return 0;
  651. }
  652. /*
  653.     Old U.S. callsign display format:
  654.     Buckmaster CD-ROM October 1991
  655.       *** Record #   452100:***
  656. Call:   KB7YW
  657.         FREDERICK A PEACHMAN
  658.         7186 NORTHVIEW DR
  659.         BROOKFIELD , OH 44403
  660. Born:   1954
  661. Class:  EXTRA
  662. Exp:    March 29, 1998
  663.  */
  664. static int
  665. display_usa(us,s)
  666. void *us;
  667. int s;
  668. {
  669. struct usa *u;
  670. char daystr[20];
  671. int yeardate;
  672. char *Unknown = "%sUnknown Expiration Date\n";
  673.  
  674. /* Sat  05-02-1992  Here I am inserting code to recognize license class 'X',
  675.   which is Buckmaster's way of saying that the license has expired because
  676.   the licensee has changed his callsign - for whatever reason. This is only
  677.   a possibility with the USA database and then only for CD's dated april
  678.   '92 or later. See 'display_x()', above.
  679.     I have commented out my old display format. Gonna simplify it
  680.   somewhat - KB7YW */
  681.  
  682.   u = (struct usa *)us;
  683.  
  684.   if (u->class[0] == 'X')  {
  685.     display_x(us,s);
  686.     return -2;  /* -2 is a flag for the caller to recognize an 'X' record */
  687.   }
  688. /*   usprintf(s, "CALL:   "); */
  689.   disp(u->callsign,sizeof(u->callsign),s);
  690. /*   usprintf(s,"\n%s", TAB); */
  691.   usprintf(s, "\n");
  692.   disp(u->firstname,sizeof(u->firstname),s);
  693.   disp(u->middle,sizeof(u->middle),s);
  694.   usprintf(s," ");
  695.   disp(u->lastname,sizeof(u->lastname),s);
  696. /*   usprintf(s,"\n%s", TAB); */
  697.   usprintf(s, "\n");
  698.   disp(u->street,sizeof(u->street),s);
  699. /*   usprintf(s,"\n%s", TAB); */
  700.   usprintf(s, "\n");
  701.   disp(u->city,sizeof(u->city),s);
  702.   usprintf(s,", ");
  703.   disp(u->state,sizeof(u->state),s);
  704.   usprintf(s," ");
  705.   disp(u->zip,sizeof(u->zip),s);
  706.   if (u->born[0] != '-')  {
  707.     usprintf(s,"\nBorn 19");
  708.     disp(u->born,sizeof(u->born),s);
  709.   }
  710.   usprintf(s,"\nClass:  ");
  711.  
  712.   switch(u->class[0])   {
  713.     case 'N':
  714.     usprintf(s,"NOVICE");
  715.     break;
  716.  
  717.     case 'T':
  718.     usprintf(s,"TECHNICIAN");
  719.     break;
  720.  
  721.     case 'C':
  722.     usprintf(s, "CLUB STATION");
  723.     break;
  724.  
  725.     case 'G':
  726.     usprintf(s,"GENERAL");
  727.     break;
  728.  
  729.     case 'A':
  730.     usprintf(s,"ADVANCED");
  731.     break;
  732.  
  733.     case 'E':
  734.     usprintf(s,"EXTRA");
  735.     break;
  736.  
  737.     default:
  738.     usprintf(s,"%c", u->class[0]);
  739.   }
  740.   usprintf(s,"\n");
  741.  
  742.   yeardate = yrval(u->expiryr);
  743.   if (day_calc(u->expirday, daystr, u->expiryr) != NULL)  {
  744.     if (daystr[0] != '\0')  {
  745.       if ((u->exp[0] == ' ') || (yeardate > 2000))  {
  746.         usprintf(s,"Expires ");
  747.         usprintf(s,"%s\n", daystr);
  748.       }
  749.       else usprintf(s,Unknown,TAB);
  750.     }
  751.     else usprintf(s,Unknown,TAB);
  752.   }
  753.   return 0;
  754. }
  755.  
  756. /*---------- Procedures specific to Canadian Callsign DataBase----------------*/
  757. static int
  758. display_canada(us,s)
  759. void *us;
  760. int s;
  761. {
  762. struct canada *u;
  763. #define DISP(x) {usprintf(s,"\n        ");\
  764.                  disp(x, sizeof(x),s);}
  765.  
  766.   u = (struct canada *) us;
  767.  
  768.   DISP(u->callsign);
  769.   DISP(u->name);
  770.   DISP(u->street);
  771.   DISP(u->town);
  772.   disp(u->zip, sizeof(u->zip),s);
  773.   usprintf(s,"\n");
  774.   usprintf(s,"%sCANADA\n",TAB);
  775.  
  776.   return 0;
  777. }
  778. /* comp_canada_calls compares the sought-for callsign with a mask of the
  779.    type encountered in the callsign field of a struct canada,
  780.  
  781.   returns 0 if they match, -1 if mask1 < mask2, 1 if mask1 > mask2.
  782.   mask1 is the callsign requested, mask2 is the database callsign from
  783.   the record under test for match.
  784.  */
  785.  
  786. static int
  787. comp_canada_calls(mask1, mask2)
  788. char mask1[6];
  789. char mask2[6];
  790. {
  791. int i;
  792. char *p, *q;
  793.  
  794.   p = mask1, q = mask2;
  795.   for (i =0; i < 6; i++)  {
  796.     if (*p != *q)  return (int) *p - (int) *q;
  797.     p++, q++;
  798.   }
  799.   return 0;
  800. }
  801. /* One of three public  functions!  */
  802. int
  803. cb_lookup(s,call)
  804. int s;
  805. char  *call;
  806. {
  807. /* This is the launcher.  Get rid of any callsign validity-checking code
  808.   that happens before calling cb_lookup. Eventually we will have to
  809.   launch the US, Canadian, or foreign Buckmaster CD databases. For right
  810.   now, tho, we only have USA and CANADA.
  811.  
  812.   For April '92 CD we only have USA! - KB7YW
  813.  
  814.     Sat  05-02-1992  Here I am inserting code to recognize license class 'X',
  815.   which is Buckmaster's way of saying that the license has expired because
  816.   the licensee has changed his callsign - for whatever reason. This is only
  817.   a possibility with the USA database and then only for CD's dated april
  818.   '92 or later - KB7YW
  819.  */
  820. char *q;
  821. int len, j;
  822. char mask[7];
  823. struct database_activity DA;
  824. char *cant = "Can't handle callsign \"%s\"\n";
  825. struct ftime ft;
  826. struct usa *u;
  827.  
  828.                   /* FIRST TEST CALLSIGN FOR VALIDITY */
  829.  
  830.   /* Buckmaster only matches callsigns of 4 to 6 letters in length  */
  831.   len = strlen(call);
  832.   if ((len < 4) || (len > 6)) return invalid_callsign(call,s);
  833.  
  834.   for (j = 0; j < 6; j++) call[j] = toupper(call[j]);
  835.  
  836.                   /* every character must be alphanumeric */
  837.   q = call;
  838.   for (j = 0; j < len; j++) if (!(isalnum(*q++)))
  839.     return invalid_callsign(call,s);
  840.  
  841.   q = call;
  842.   switch (*q) {
  843.     case 'A':
  844.     case 'K':
  845.     case 'N':
  846.     case 'W':
  847.     if ((init(&DA, USA, s)) == -1)  return 0;
  848.     if ((make_mask(mask, call, s)) == -1) {
  849.       close_down(&DA);
  850.       return 0;
  851.     }
  852.     break;
  853.  
  854.     case 'V':
  855.       if ((strncmp(call,"VO",2) == 0) || (strncmp(call,"VE",2) == 0)) {
  856.         if ((init(&DA, CANADA, s)) == -1)  return 0;
  857.         if ((make_mask(mask, call, s)) == -1)   {
  858.           close_down(&DA);
  859.           return 0;
  860.         }
  861.       }
  862.       else  {
  863.         usprintf(s,cant,call);
  864.         return 0;
  865.       }
  866.       break;
  867.  
  868.     default:
  869.         usprintf(s,cant,call);
  870.       return 0;
  871.   }
  872.  
  873.   if ((find_call(&DA,mask)) == -1)
  874.     usprintf(s, "\n\nCallsign \"%s\" not found\n\n",call);
  875.   else {
  876.     while (displayrec(&DA,s) == -2)  {
  877. /* If we got to here, we are dealing with an 'X' record, which is only a
  878.   possibility in the USA database. (Of course now (Sat  05-02-1992), we
  879.   only have the U.S. database to play with as of April '92 HamCall CD).
  880.   Soon we can get rid of the Canadian stuff, since the CD's that support
  881.   it will be too old to use.
  882.  */
  883.         u = (struct usa *) DA.record_buf;
  884.  
  885. /* Buckmaster will have filled out u->firstname as: "∙SEE∙KF8PH∙". So
  886.    our new callsign to look up is at position 5 in u->firstname!
  887.  */
  888.         strncpy(call, &u->firstname[5], 6);/* put in the new callsign !!! */
  889.         if ((make_mask(mask, call, s)) == -1)   {
  890.           close_down(&DA);
  891.           return 0;
  892.         }
  893.       if ((find_call(&DA,mask)) == -1)  {
  894.         usprintf(s, "\n\nCallsign \"%s\" not found\n\n",call);
  895.         break;  /* Get out of what might otherwise be an infinite loop  */
  896.       }
  897.     }
  898.     getftime(DA.handle, &ft);
  899.     usprintf(s,"\nDatabase date: %s %d, %02d\n\n\n",
  900.       month[ft.ft_month-1].m, ft.ft_day, ft.ft_year+1980);
  901.   }
  902.     /* find_call returns with appropriate record already read into
  903.        DA.record_buf and the return value is -1 for error or number of
  904.        seeks required on success.
  905.      */
  906.     
  907.   close_down(&DA);
  908.   return 0;
  909. }
  910.  
  911. #else   /* #ifndef ICALL  i.e. ICALL is now defined, & here's what you get: */
  912.  
  913. /* Buckmaster's international callsign database - new April '92             */
  914. long Mincoreleft = 77000L;      /* minimum coreleft needed for icall.exe    */
  915. int init_Database(char *);      /* public - used by cdbstart in callcdb.c   */
  916. static int get_Database_date(char *);
  917. char *Database_date = NULLCHAR; /* set once in get_Database_date()          */
  918. char *Database = NULLCHAR;      /* set by init_Database()                   */
  919. char *db = "/ham0/hamcall.all"; /* default initialized address for Database */
  920.  
  921. int
  922. cb_lookup(s,call)
  923. int s;
  924. char  *call;
  925. {
  926.   FILE *fp, *fd;
  927.   char command[50];
  928.   char file[20], dosfile[20];
  929.   int fhandle, retval;
  930.   long filesize;
  931.   char *q, *p;
  932.  
  933.   if (coreleft() < Mincoreleft) {
  934.     usprintf(s,
  935. "\n\n\tLow System Memory !!!.\n\
  936. \tAlert sysop @ %s:\n\
  937. \tCannot service callsign -\n\
  938. \tdatabase requests until\n\
  939. \tprogram reboots.\n\n", Callserver);
  940.     log(s,"callserver failure [insufficient memory]");
  941.     return 0;
  942.   }
  943.  
  944.   if (Database == NULLCHAR)
  945.     init_Database(NULLCHAR);
  946.  
  947.   tmpnam(file);
  948.   strcpy(dosfile, file);
  949.   q = dosfile;
  950.  
  951.   while (*q != '\0')  {
  952.     if (*q == '/') *q = '\\'; /* make slashes into backslashes for MS-DOS */
  953.     q++;
  954.   }
  955.  
  956.   sprintf(command,"%s\\icall.exe %s %s *> %s",CDROM, CDROM, call, dosfile);
  957.  
  958.   retval = system(command);
  959.  
  960.   if (!retval)  {
  961.     if((fp = fopen(file,READ_TEXT)) != NULLFILE) {
  962.         sendfile(fp,s,ASCII_TYPE,0);
  963.         if (Database_date != NULLCHAR)
  964.           usprintf(s, "\n\nDatabase date: %s\n\n\n", Database_date);
  965.         fclose(fp);
  966.         remove(file);
  967.         return 0;
  968.     }
  969.   }
  970.   usprintf(s,"Could not open database - please try later\n\n");
  971.   return 0;
  972. }
  973. #endif  /* #ifndef ICALL */
  974. #endif /* #ifdef CALLSERVER */
  975.  
  976. struct cmds Callserver_cmds[] = {
  977.   "hostname", docallserver_hostname, 0,  0,  NULLCHAR,
  978. #ifdef CALLSERVER     /* not used if only CALLCLI is defined  */
  979.   "database", docallserver_databases,  0,  0,  NULLCHAR,
  980. #endif
  981.   NULLCHAR,
  982. };
  983.  
  984. /* Another public, headered in commands.h */
  985. int
  986. #ifdef PROTOTYPES
  987. docallserver(int argc,char **argv,void *p)
  988. #else
  989. docallserver(argc,argv,p)
  990. int argc;
  991. char *argv[];
  992. void *p;
  993. #endif
  994. {
  995.   return subcmd(Callserver_cmds, argc, argv, p);
  996. }
  997.  
  998. static int
  999. docallserver_hostname(argc,argv,p)
  1000. int argc;
  1001. char *argv[];
  1002. void *p;
  1003. {
  1004.     if(argc < 2)
  1005.     {
  1006.         if(Callserver != NULLCHAR)
  1007.       tprintf("The callserver's hostname is: %s\n",Callserver);
  1008.         else
  1009.         {
  1010.             tprintf("Callserver not configured!\n");
  1011.       tprintf("Usage: callserver <hostname>|<ip_address>\n");
  1012.         }
  1013.     }
  1014.     else {
  1015.         if(Callserver != NULLCHAR)
  1016.             free(Callserver);
  1017.         Callserver = strdup(argv[1]);
  1018.     }
  1019.     return 0;
  1020. }
  1021. #ifdef CALLSERVER
  1022. #ifdef ICALL
  1023.  
  1024. /* For the new (May '92) HamCall CD the  callserver database is
  1025. "/ham0/hamcall.all" unless the user specifies otherwise
  1026.  */
  1027.  
  1028. static int
  1029. get_Database_date(db)
  1030. char *db; /* temporary string contains putative database filename  */
  1031. {
  1032. FILE *fd;
  1033. int fhandle;
  1034. struct ftime ft;
  1035. char tmpstr[50];
  1036. char database[50];
  1037.  
  1038. /*  CDROM contains drive letter + ':', e.g. "s:"
  1039.     db contains the rest of the path + database file name, e.g.
  1040.     "/ham0/hamcall.exe".
  1041.  */
  1042.     sprintf(database, "%s%s", CDROM, db);
  1043.  
  1044.     if ((fd = fopen(database, "rb")) != NULLFILE) {
  1045.       fhandle = fileno(fd);
  1046.       getftime(fhandle, &ft);
  1047.       sprintf(tmpstr,"%s %d, %02d",
  1048.         month[ft.ft_month-1].m, ft.ft_day, ft.ft_year+1980);
  1049.       fclose(fd);
  1050.       if (Database_date != NULLCHAR) free(Database_date);
  1051.       Database_date = strdup(tmpstr); /* Now it's initialized!! */
  1052.       return 0;
  1053.     }
  1054.     else return -1;   /* Database could not be opened for binary read */
  1055. }
  1056.  
  1057. /* public: called when the ICALL callserver is started. db must be allocated
  1058.     with strdup unless it is to be assigned to the global char *db,
  1059.     declared this module. In which case db should be passed as NULLCHAR.
  1060.  */
  1061.  
  1062. int
  1063. init_Database(tmp_db)
  1064. char *tmp_db;
  1065. {
  1066. extern char *db;  /* global: "/ham0/hamcall.all"  */
  1067.  
  1068.     if (tmp_db == NULLCHAR) tmp_db = db;
  1069.  
  1070.     if (Database == NULLCHAR)
  1071.       if (CDROM == NULLCHAR)  {
  1072.         tprintf(cdrom_prompt);
  1073.         return -1;
  1074.       }
  1075.       if (get_Database_date(tmp_db) == 0) {
  1076.         Database = tmp_db;
  1077.         return 0;
  1078.       } else  {
  1079.         tprintf(
  1080.           "\t%c%s could not be found.\n\
  1081. \tPlace \"Ham Call\" CD in CD-ROM drive \"%s\" -OR\n",'\007',tmp_db, CDROM);
  1082.         tprintf(
  1083.           "\tspecify alternate callserver database filename.\n");
  1084.         return -1;
  1085.       }
  1086. }
  1087.  
  1088. static int
  1089. docallserver_databases(argc,argv,p)
  1090. int argc;
  1091. char *argv[];
  1092. void *p;
  1093. {
  1094. char *tmpstr;
  1095. char *cs = "callserver database";
  1096.  
  1097.   if (argc == 1 ) {
  1098.       tprintf("%s ", cs);
  1099.       if (Database == NULLCHAR) {
  1100.         tprintf("not configured.\n"); /* Will not be configured unless
  1101.                                          user has already used the "cdrom"
  1102.                                          command, and optionally
  1103.                                          "callserver database </path/filename>"
  1104.                                          as well as "start callbook".
  1105.                                        */
  1106.         if (CDROM == NULLCHAR)
  1107.           tprintf(cdrom_prompt);
  1108.       }
  1109.       else  tprintf("is \"%s\" (dated %s)\n", Database, Database_date);
  1110.       return 0;
  1111.   } else if (argc >= 2)   {
  1112.     tmpstr = strdup(argv[1]);
  1113.     if (init_Database(tmpstr) == 0) {
  1114.       return 0;
  1115.     } else  {
  1116.       free(tmpstr);
  1117.       /* no error reporting. init_Database() does plenty of that  */
  1118.       return -1;
  1119.     }
  1120.   }
  1121. }
  1122.  
  1123.  
  1124. #else       /* #ifdef ICALL i.e. ICALL is NOT defined here. You use this
  1125.                 with the old-style database  */
  1126. static int
  1127. docallserver_databases(argc,argv,p)
  1128. int argc;
  1129. char *argv[];
  1130. void *p;
  1131. {
  1132. int t;
  1133.  
  1134.   if (argc < 2) {
  1135.     for (t = 0; t < DATABASE_TYPES; t++)  {
  1136.       tprintf("callserver database %s ", database_label[t]);
  1137.       if (database[t] == NULLCHAR)  {
  1138.         tprintf("not configured.\n");
  1139.       } else  tprintf("%s\n", database[t]);
  1140.     }
  1141.     return 0;
  1142.   } else  { /* argc >= 2 */
  1143.       for (t = 0; t < DATABASE_TYPES; t++)  {
  1144.         if (strncmp(database_label[t],argv[1],strlen(argv[1])) == 0)  {
  1145.           if (argc < 3) {
  1146.             tprintf("callserver database %s ", database_label[t]);
  1147.             if (database[t] == NULLCHAR)  tprintf("not configured\n");
  1148.             else  tprintf("%s\n", database[t]);
  1149.           } else  { /* argc >= 3  */
  1150.             if (database[t] == NULLCHAR)  free(database[t]);
  1151.             database[t] = strdup(argv[2]);
  1152.           }
  1153.           return 0; /* we have found our match with database_label[t] */
  1154.         }
  1155.       }
  1156.       /* no match with database_label: which database?  */
  1157.       tprintf("Usage: callserver database ");
  1158.       for (t = 0; t < DATABASE_TYPES; t++)  {
  1159.         tprintf("%s", database_label[t]);
  1160.         if ( t < DATABASE_TYPES - 1)  tprintf("|");
  1161.       }
  1162.       tprintf(" <database drive:/path/filename>\n");
  1163.       return -1;
  1164.   }
  1165.   /* not reached  */
  1166. }
  1167. #endif  /* #ifdef ICALL  */
  1168.  
  1169. /* the last public of this module, also headered in commands.h  */
  1170. int
  1171. docdrom(argc,argv,p)
  1172. int argc;
  1173. char *argv[];
  1174. void *p;
  1175. {
  1176. extern char *CDROM; /* declared above, this module  */
  1177.  
  1178.   if (argc < 2) {
  1179.     if (CDROM == NULLCHAR)  {
  1180.       tprintf("CDROM drive letter not specified\n");
  1181.     }
  1182.     else  tprintf("CDROM drive is \"%s\"\n", CDROM);
  1183.     return 0;
  1184.   }
  1185.   else  {
  1186.     if ((argv[1][2] == '\0')    &&
  1187.         (isalpha(argv[1][0]))   &&
  1188.         (argv[1][1] == ':'))  {
  1189.           if (CDROM != NULLCHAR)  free(CDROM);
  1190.           CDROM = strdup(argv[1]);
  1191.           return 0;
  1192.     }
  1193.     else  {
  1194.       tprintf("Usage: \"cdrom driveletter:\", e.g. \"cdrom s:\"\n");
  1195.       return 1;
  1196.     }
  1197.   }
  1198.   /* not reached  */
  1199. }
  1200. #endif  /* #ifdef CALLSERVER  */
  1201.